<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>修改编码生成器</title>
	<#include "./comm/meta-base.ftl" />
	<#include "./comm/meta-easyui.ftl" />
	<#include "./comm/meta-comm.ftl" />
	<link href="${basePath}/static/css/keycode.css" rel="stylesheet" />
	
</head>
<body>
		
<form id="data_form" role="form" class="page-form"   method="post" >
	<div class="buts-row-top row ">
			<a href="javascript:submitForm();"  class="btn btn-success">
				<i class="fa fa-check"></i>提 交</a>
			<a href="javascript:MainTab.closeTabAndRefresh('编码生成器管理')" class="btn btn-default">
				<i class="fa fa-times"></i>取 消</a>
	</div>
	<div class="but-row-top-shadow"></div>
	
 	<!--表单块-->
	<div class="form-title">编码生成器配置</div>
	<div class="row">
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">编码生成器标识</label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="keycodeId" id="keycodeId" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,64]','remote[\'${basePath}/keycode/keycode-keycodeId-validate?oldKeycodeId=${upmsKeycodeGeneratorPO.keycodeId}\' ,\'keycodeId\']' ]" value="${upmsKeycodeGeneratorPO.keycodeId }" />
			</div>
		</div>
		
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">生成器名称</label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="generatorName" id="generatorName" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]']"  value="${upmsKeycodeGeneratorPO.generatorName }" />
			</div>
		</div>
		
	</div>
	
	<div class="form-title">生成器配置</div>
	
	<div class="sm-title">日期格式配置</div>
	<div class="row">
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">日期格式 </label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="dateFormat" id="dateFormat" class="form-control easyui-validatebox" 
					data-options="validType:['length[1,128]']" value="${upmsKeycodeGeneratorPO.dateFormat}" />
			</div>
			
		</div>
		
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">日期值</label>
			<div class="col-sm-7 fm-control">
				<input type="text" name="dateValue" id="dateValue" class="form-control easyui-validatebox" 
					data-options="validType:['length[1,128]']" value="${upmsKeycodeGeneratorPO.dateValue}" />
			</div>
			<div class="col-sm-2 ">
				<a href="javascript:currentDateValue();" class="btn  btn-primary">当前日期</a>
			</div>
			
		</div>
	</div>
	
	<hr/>
	
	<div class="sm-title">序列格式配置</div>
	<div class="row">
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">序列起始值</label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="sequenceStart" id="sequenceStart" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]','number']" value="${upmsKeycodeGeneratorPO.sequenceStart}"  />
			</div>
		</div>
		
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">序列长度</label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="sequenceLength" id="sequenceLength" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]','number']"  value="${upmsKeycodeGeneratorPO.sequenceLength}" />
			</div>
		</div>
		
		<div class="form-group col-sm-4 ">
			<div class="checkbox col-sm-12">
	            <label>
	            	<#if upmsKeycodeGeneratorPO.isSequenceDateIncrement > 
	                	<input type="checkbox" name="isSequenceDateIncrement" value="1"   checked="checked"/>
	                <#else>
	                	<input type="checkbox" name="isSequenceDateIncrement" value="1"   />
	                </#if> 
	                <span class="text">是否序列按日期自增</span>
	            </label>
	        </div>
		</div>
	</div>
	
	<div class="row" >
	
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">序列当前值</label>
			<div class="col-sm-7 fm-control">
				<input type="text" name="sequenceCurrentValue" id="sequenceCurrentValue" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]','number']" value="${upmsKeycodeGeneratorPO.sequenceCurrentValue}"/>
			</div>
			<div class="col-sm-2 " >
				<a href="javascript:sequenceCurrentValue();" class="btn  btn-primary">序列值</a>
			</div>
		</div>
	
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">序列进制</label>
			<div class="col-sm-9 fm-control">
				<input type="text" name="sequenceDigits" id="sequenceDigits" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]','number']" value="${upmsKeycodeGeneratorPO.sequenceDigits}"/>
			</div>
		</div>
		
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">序列进制值</label>
			<div class="col-sm-7 fm-control">
				<input type="text" name="sequenceDigitsValue" id="sequenceDigitsValue" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]']" value="${upmsKeycodeGeneratorPO.sequenceDigitsValue}"  />
			</div>
			<div class="col-sm-2 " >
				<a href="javascript:sequenceDigitsValue();" class="btn  btn-primary">进制值</a>
			</div>
		</div>
		
		
	</div>
	
	
	
	<div class="form-title">表达式配置</div>
	<div class="row">
		<div class="form-group col-sm-12 ">
			<label class="col-sm-1 fm-label">表达式配置</label>
			<div class="col-sm-11 fm-control">
				<ul class="expul">
					<li  class="exp-null">编辑表达式(右键)：</li>
					${expHtml}
				</ul>
			</div>
		</div>
	</div>
	<div class="row" >
	
		<div class="form-group col-sm-12 ">
			<label class="col-sm-1 fm-label">编码表达式:</label>
			<label class="col-sm-11 fm-control" id="expStr" style="text-align:left;font-weight:bold;font-size:18px;">
				 ${upmsKeycodeGeneratorPO.expression}
			</label>
			<input type="hidden" id="expression" name="expression"  value="${upmsKeycodeGeneratorPO.expression}"  />
		</div>
	</div>
	
	
	<div class="row">	
		<div class="form-group col-sm-4 ">
			<label class="col-sm-3 fm-label">编码当前值</label>
			<div class="col-sm-7 fm-control">
				<input type="text" name="keycodeCurrentValue" id="keycodeCurrentValue" class="form-control easyui-validatebox" 
					data-options="required:true,validType:['length[1,128]']"  value="${upmsKeycodeGeneratorPO.keycodeCurrentValue}" />
			</div>
			<div class="col-sm-2 " >
				<a href="javascript:keycodeCurrentValue()" class="btn  btn-primary">编码当前值</a>
			</div>
		</div>
	</div>

 </form>
 
    <!-- 右键菜单 -->
    <div id="tab_rightmenu" class="dropdown-container hidden" style="position:absolute; z-index:999">
        <div class="dropdown-preview">
            <ul class="dropdown-menu">
                <li><a class="exp-text" href="javascript:appendElement('text')"><i class="dropdown-icon fa fa-font"></i>|追加文本</a></li>
                <li><a class="exp-date" href="javascript:appendElement('date')" ><i class="dropdown-icon fa fa-calendar"></i>|追加日期</a></li>
                <li><a class="exp-sequence" href="javascript:appendElement('sequence')" ><i class="dropdown-icon fa fa-tasks"></i>|追加序列</a></li>
                <li><a class="exp-params" href="javascript:appendElement('params')" ><i class="dropdown-icon fa fa-pagelines"></i>|追加自定义参数</a></li>
                <li class="divider"></li>
                <li><a class="exp-mv" href="javascript:elmMove('prev')" ><i class="dropdown-icon fa fa-arrow-left"></i>|向前移动</a></li>
                <li><a class="exp-mv" href="javascript:elmMove('next')" ><i class="dropdown-icon fa fa-arrow-right"></i>|向后移动</a></li>
                <li><a class="exp-remove" href="javascript:removeElement()" ><i class="dropdown-icon fa  fa-minus"></i>|删除对象</a></li>
            </ul>
        </div>
    </div>
	<!-- /右键菜单 -->
 
 
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
	bindExpContextmenu();
	$("body").bind('click',function(){
		$("#tab_rightmenu").addClass("hidden");
	});

});

function keycodeCurrentValue(){
	var expression=$("#expression").val();
	var sequenceDigitsValue=$("#sequenceDigitsValue").val();
	var dateValue=$("#dateValue").val();
	
	var pdata={'expression':expression,
	'sequenceDigitsValue':sequenceDigitsValue,
	'dateValue':dateValue}
	
	$.post("${basePath}/keycode/keycode-keycodeCurrentValue",pdata, function(data) {
		$("#keycodeCurrentValue").prop("value",data);
		$.parser.parse($("#data_form"));	
	});
}

function currentDateValue(){
	var dateFormat=$("#dateFormat").val();
	$.post("${basePath}/keycode/keycode-dateValue",{'dateFormat':dateFormat}, function(data) {
		$("#dateValue").prop("value",data);
		$.parser.parse($("#data_form"));	
	});
}

function sequenceDigitsValue(){
	var sequenceStart=$("#sequenceStart").val();
	var sequenceLength=$("#sequenceLength").val();
	var sequenceDigits=$("#sequenceDigits").val();
	var sequenceCurrentValue=$("#sequenceCurrentValue").val();
	
	var pdata={'sequenceStart':sequenceStart,
	'sequenceLength':sequenceLength,
	'sequenceDigits':sequenceDigits,
	'sequenceCurrentValue':sequenceCurrentValue}

	$.post("${basePath}/keycode/keycode-sequenceDigitsValue",pdata, function(data) {
		$("#sequenceDigitsValue").prop("value",data);
		$.parser.parse($("#data_form"));	
	});
}

function sequenceCurrentValue(){
	var sequenceStart=$("#sequenceStart").val();
	var sequenceLength=$("#sequenceLength").val();
	var sequenceDigits=$("#sequenceDigits").val();
	var sequenceDigitsValue=$("#sequenceDigitsValue").val();
	
	var pdata={'sequenceStart':sequenceStart,
	'sequenceLength':sequenceLength,
	'sequenceDigits':sequenceDigits,
	'sequenceDigitsValue':sequenceDigitsValue}

	$.post("${basePath}/keycode/keycode-sequenceCurrentValue",pdata, function(data) {
		$("#sequenceCurrentValue").prop("value",data);
		$.parser.parse($("#data_form"));	
	});
}


//移动
function elmMove(direction){
	var $curElm=$($(".expul .checked")[0]);
	var $prevElm=$curElm.prev();
	var $nextElm=$curElm.next();
	
	if(direction=='prev'&&$prevElm.length>0&&!$prevElm.hasClass("exp-null")){
		$prevElm.before($curElm.prop("outerHTML"));
		
		var val="";
		if($curElm.find(".exp-inputtext").length>0){
			val=$curElm.find(".exp-inputtext").val();
			$prevElm.prev().find(".exp-inputtext").prop("value",val);
		}
		
		$curElm.remove();
	}
	
	if(direction=='next'&&$nextElm.length>0&&!$curElm.hasClass("exp-null")){
		$nextElm.after($curElm.prop("outerHTML"));
		
		var val="";
		if($curElm.find(".exp-inputtext").length>0){
			val=$curElm.find(".exp-inputtext").val();
			$nextElm.next().find(".exp-inputtext").prop("value",val);
		}
		
		$curElm.remove();
	}
	
	
	bindExpContextmenu();
	bindInputTextblur();
	buildExp();
}


//追加对象
function appendElement(type){

	var $curElm=$($(".expul .checked")[0]);
	
	var htm="";
	
	if(type=='text'){
		htm="<li  class=\"exp-text\"><input type=\"text\" class=\"exp-inputtext\" /></li>";
	}
	if(type=='date'){
		htm="<li  class=\"exp-date\">[日期]</li>";
	}
	if(type=='sequence'){
		htm="<li  class=\"exp-sequence\">[序列]</li>";
	}
	if(type=='params'){
		htm="<li  class=\"exp-params\"><input type=\"text\" class=\"exp-inputtext\" /></li>";
	}
	$curElm.after(htm);
	bindExpContextmenu();
	bindInputTextblur();
	buildExp();
		
}
function removeElement(){
	var $curElm=$($(".expul .checked")[0]);
	$curElm.remove();
	buildExp();
}

//生成表达式
function buildExp(){
	var exp="";

	var $lis=$(".expul li");
	for(var i=0;i<$lis.length;i++){
		var $li=$($lis[i]);
		if($li.hasClass('exp-text')){
			var str=$li.find(".exp-inputtext").val();
			exp=exp+str;
		}
		
		if($li.hasClass('exp-date')){
			var str="[exp-date]";
			exp=exp+str;
		}
		
		if($li.hasClass('exp-sequence')){
			var str="[exp-sequence]";
			exp=exp+str;
		}
		
		if($li.hasClass('exp-params')){
			var str=$li.find(".exp-inputtext").val();
			str="[param-"+str+"]";
			exp=exp+str;
		}
	}
	
	$("#expStr").text(exp);
	$("#expression").prop("value",exp);
	

}

//绑定失去焦点
function bindInputTextblur(){
	$(".expul .exp-inputtext").bind("blur",function(){
		buildExp();
	});  
}

 


//绑定右键
function bindExpContextmenu(){
	$(".expul li").bind('contextmenu',function(e){
		$("#tab_rightmenu").css({
			left: e.pageX,
			top: e.pageY
		});
		$("#tab_rightmenu").removeClass("hidden");
		
		$(".expul li").removeClass("checked");
		var $this=$(this);
		$this.addClass("checked");
		
		return false;
	});
}



//提交表单
function submitForm(){
	$("#data_form").form('submit', {
		url : '${basePath}/keycode/keycode-update',
		onSubmit: function (){
			showPageShade();//当提交时候，显示遮罩层
			if(!$(this).form('validate')){//页面验证
				hiddenPageShade();//未成功，隐藏遮罩层
				return false;
			}
			return true;
        },
		success : function(result) {
			hiddenPageShade();//成功后，隐藏遮罩层
			MainTab.closeTabAndRefresh("编码生成器管理");
		}
	});
}




</script>


